package com.dlc.shop.seckill.api.listener;

import com.dlc.shop.bean.event.SeckillStockEvent;
import com.dlc.shop.seckill.common.model.SeckillSku;
import com.dlc.shop.seckill.common.service.SeckillSkuService;
import lombok.AllArgsConstructor;
import org.springframework.context.event.EventListener;
import org.springframework.stereotype.Component;

/**
 * 支付时校验订单过期事件
 * @author lhd
 */
@Component("secKillStockListener")
@AllArgsConstructor
public class SecKillStockListener {
    private final SeckillSkuService seckillSkuService;

    @EventListener(SeckillStockEvent.class)
    public void checkSecKillOrderHandle(SeckillStockEvent event) {
        SeckillSku seckillSku = seckillSkuService.getSeckillSkuById(event.getSeckillSkuId());
        Long stockPointId = seckillSku.getSeckillStockPointSkuList().get(0).getStockPointId();
        event.setDefaultStockPointId(stockPointId);
    }

}
